package com.dlry.db;

import java.sql.Timestamp;
import java.util.List;

import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.dlry.entity.DlMeetingRoom;
import com.dlry.entity.DlMeetingRoomBooking;

public interface MeetingRoomRepository extends JpaRepository<DlMeetingRoom, Long> {

	Page<DlMeetingRoom> findAll(Pageable arg0);

	long count();

	void delete(DlMeetingRoom arg0);

	void delete(Iterable<? extends DlMeetingRoom> arg0);

	void delete(Long arg0);

	void deleteAll();

	boolean exists(Long arg0);

	DlMeetingRoom findOne(Long arg0);

	<S extends DlMeetingRoom> S save(S arg0);

	<S extends DlMeetingRoom> long count(Example<S> arg0);

	<S extends DlMeetingRoom> boolean exists(Example<S> arg0);

	<S extends DlMeetingRoom> Page<S> findAll(Example<S> arg0, Pageable arg1);

	<S extends DlMeetingRoom> S findOne(Example<S> arg0);

	List<DlMeetingRoom> findAll();

	List<DlMeetingRoom> findAll(Sort sort);

	List<DlMeetingRoom> findAll(Iterable<Long> ids);

	<S extends DlMeetingRoom> List<S> save(Iterable<S> entities);

	void flush();

	<S extends DlMeetingRoom> S saveAndFlush(S entity);

	<S extends DlMeetingRoom> List<S> findAll(Example<S> example);

	<S extends DlMeetingRoom> List<S> findAll(Example<S> example, Sort sort);

	@Query("select count(*) from DlMeetingRoom m inner join m.bookings as b where m.id = ?1")
	Long getBookingCountByMId(Long rId);

	@Query("select b from DlMeetingRoom m inner join m.bookings as b where m.id = ?1 and b.endTime >= ?2")
	List<DlMeetingRoomBooking> getBookingsByIdFrom(Long rId, Timestamp timestamp);

	@Query("select b from DlMeetingRoom m inner join m.bookings as b where m.id = ?1 and b.endTime >= ?2 and b.bookingTime <= ?3")
	List<DlMeetingRoomBooking> getBookingsByIdBetween(Long rId, Timestamp startDay, Timestamp entDay);
}
